﻿// 主程序入口

using System;
using System.Diagnostics;

namespace AdjPlane
{
    class Program
    {
        static void Test()
        {
            string path1 = @"E:\data\CP\交叉导线网\InPushG(540,-35)(BYL10H-7--ZD30-1).in2";
            string path2 = @"E:\data\CP\交叉导线网\InPushG(895,-25)(DS2CPII29--XGNCPI54-2).in2";
            string path3 = @"E:\data\CP\交叉导线网\InPushG(1000,-35)(CZ3--ZXZ6).in2";
            string path4 = @"E:\data\CP\旁点导线网\LongLine.in2";
            string path5 = @"E:\data\CP\旁点导线网\CKPointD-Z-JKPointC-42stnsgc.in2";
            string path6 = @"E:\data\CP\自由测站边角交会网\InPushG(1000,-35)(0275C03--TCY71).in2";
            string path7 = @"E:\data\CP\自由测站边角交会网\InPushG(1000,-35)(0273C01--ZJM15).in2";

            string t1 = @"E:\data\CP\test\pn.in2";
            string t3 = @"E:\data\CP\test\测图导线网.in2";
            string t4 = @"E:\data\CP\test\特殊网.in2";
            string t5 = @"E:\data\CP\test\特种施工平面控制网.in2";
            string t6 = @"E:\data\CP\test\城市二等网.in2";
            string t7 = @"E:\data\CP\test\附合导线.in2";

            // 平面网平差
            for (double i = 0; i < 1; i += 1)
            {
                File_t fopt = new File_t
                {
                    infile = path1,
                    oufile= null,
                    xyhfile=null,
                    approxfile=null,
                    SysErrFile=null,
                    approx_3s=null,
                };
                Robust_t rbopt = new Robust_t
                {
                    robust0 = Robust0.LS,
                    WgtFunc = WeightFunc.Huber,
                    K0 = 1.5,
                    K1 = 3,
                };
                SemiParam_t spopt = new SemiParam_t
                {
                    regularParam = RegularParam.Lcurve,
                    R_Order = 1,
                };
                Gyro_t gyopt = new Gyro_t
                {
                    UseGyro = 1,
                    GyInAdp = 0,
                    GyOuAdp = 10,
                };
                Proc_t popt = new Proc_t
                {
                    AdjOpt = ADJOPT.Constriant,
                    WgtDef = Weight.Tradition,
                    Eps_X = 0.1,
                    Eps_VCE = 0.01,
                    IterMax_X = 20,
                    IterMax_VCE = 20,
                    DisWgt = 1,
                    AveDis = 1,
                    UseKnApprox = 0,
                    Approx_Trilateral = 1,
                    SideEdge = 0,
                    GyOpt = gyopt,
                    RobustOpt = rbopt,
                    SemiParamOpt = spopt,
                };

                if (popt.AdjOpt == ADJOPT.Constriant)
                {
                    Plane pn = new Plane();
                    pn.PlaneAdj(popt, ref fopt);
                }
                else if (popt.AdjOpt == ADJOPT.FreeNet)
                {
                    FreeNet fn = new FreeNet();
                    fn.FreeAdj(popt, ref fopt);
                    
                }
                else if (popt.AdjOpt == ADJOPT.SemiParam)
                {
                    SemiParam sp = new SemiParam();
                    sp.PlaneAdj(popt, ref fopt);
                }
                else if(popt.AdjOpt == ADJOPT.CalApprox)
                {
                    Plane pn = new Plane();
                    pn.CalApprox(popt, ref fopt);
                }

                Process.Start("notepad.exe", fopt.oufile);
                if (popt.AdjOpt == ADJOPT.SemiParam)
                {
                    Process.Start("notepad.exe", fopt.SysErrFile);
                }
                if (popt.AdjOpt == ADJOPT.CalApprox)
                {
                    Process.Start("notepad.exe", fopt.xyhfile);
                }
            }

        }

        static void Main(string[] args)
        {
            var w = Stopwatch.StartNew();
            Test();
            Console.WriteLine("timespan:{0}",w.Elapsed.TotalSeconds);
        }
    }
}
